package Main;


import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;

/**
 * Gere les evenement clavier.
 * @author Emmanuel
 */
public class EventHandler implements KeyListener{
    
    private Personnage perso;
    private Simulator simulator;
    
    public EventHandler(Simulator s, Personnage p) {
        this.perso=p;
        this.simulator=s;
    }

    @Override
    public void keyTyped(KeyEvent e) {
        
    }

    @Override
    public void keyPressed(KeyEvent e) {
        switch(e.getKeyCode()) {
            case KeyEvent.VK_UP : 
                    perso.saute(true);
                break;
            case KeyEvent.VK_SPACE : 
                    perso.saute(true);
                break;
            case KeyEvent.VK_ESCAPE : 
                simulator.quit();
                break;
            case KeyEvent.VK_F1 : 
                // TODO show help.
                break;
            case KeyEvent.VK_DOWN : 
                if(!perso.isAllonge()) {
                   perso.allongeToi(true);
                    break;
            }
        }
    }
    
    @Override
    public void keyReleased(KeyEvent e) {
        switch(e.getKeyCode()) {
            case KeyEvent.VK_DOWN : 
                perso.allongeToi(false);
                break;
        }
    }
}
